package com.wantup.springboot.boot.quartz;

import com.wantup.springboot.boot.mapper.TxPersonMapper;
import com.wantup.springboot.boot.service.TxPersonService;
import com.wantup.springboot.boot.service.impl.TxPersonServiceImpl;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Zhaoluowei
 * @version 1.0
 * @date 2018/11/7 19:38
 */
public class HelloJob implements Job {

    //方式二：
    private String msg;
    private Double data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg1) {
        this.msg = msg1;
    }

    public Double getData() {
        return data;
    }

    public void setData(Double data) {
        this.data = data;
    }

    /**
     * 编写具体的代码
     * @param jobExecutionContext
     * @throws JobExecutionException
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

//        Date startTime = jobExecutionContext.getTrigger().getStartTime();
//        Date endTime = jobExecutionContext.getTrigger().getEndTime();
//        System.out.println("startTime : "+startTime);
//        System.out.println("endTime : "+endTime);


        //打印当前时间
            System.out.println("Quarzt 定时器 "+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            System.out.println("Hello Quarzt ");
    }


}








//    @Override
//    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
//        int count = 0;
////        try {
////            count = new TxPersonServiceImpl().getCountItem();
////        } catch (Exception e) {
////            e.printStackTrace();
////        }
//        //可以获取 它放在了 那个 jobDetail 里面
//        /*System.out.println("name "+jobExecutionContext.getJobDetail().getKey().getName());
//        System.out.println("group "+jobExecutionContext.getJobDetail().getKey().getGroup());
//        System.out.println("class "+jobExecutionContext.getJobDetail().getJobClass().getName());*/
//
//        // 通过jobKey获取到 withIdentity("myJob","group1") 参数信息
//        JobKey jobKey = jobExecutionContext.getJobDetail().getKey();
//        System.out.println("name "+jobKey.getName());
//        System.out.println("group "+jobKey.getGroup());
//
//
//        TriggerKey triggerKey = jobExecutionContext.getTrigger().getKey();
//        System.out.println("my triggerKey name and group :"+triggerKey.getName()+" : "+triggerKey.getGroup());
//
//
//        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
//        System.out.println("jobDataMap msg : "+jobDataMap.getString("msg"));
//        System.out.println("jobDataMap data : "+jobDataMap.getFloat("data"));
//
//        JobDataMap triggerMap = jobExecutionContext.getTrigger().getJobDataMap();
//        System.out.println("triggerMap msg : "+triggerMap.getString("msg"));
//        System.out.println("triggerMap data : "+triggerMap.getDouble("data"));
//
//        //job 和 trigger 合并  如果存在 键值相同  trigger 覆盖 job的值
//        JobDataMap mergedJobDataMap = jobExecutionContext.getMergedJobDataMap();
//        System.out.println(mergedJobDataMap.getString("msg"));
//        System.out.println(mergedJobDataMap.getDouble("data"));
//
//
//        //方式二： 在调度类中 通过反射的方式进行赋值
//        System.out.println("=============================");
//        System.out.println(msg);
//        System.out.println(data);
//
//
//        //打印当前时间
//        System.out.println("Quarzt 定时器 "+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
//        System.out.println("Hello Quarzt tbl_person 共有数据 : "+count);
//    }
